package com.ymttest.business.service.shenqi;

import java.io.IOException;
import java.math.BigDecimal;

import org.apache.http.client.ClientProtocolException;

import com.shop2cn.iapi.sqdistributor.parameter.request.DisablePartnerReq;
import com.shop2cn.iapi.sqdistributor.parameter.request.EnablePartnerReq;
import com.shop2cn.iapi.sqdistributor.parameter.request.SavePartnerConfigReq;
import com.shop2cn.iapi.sqdistributor.service.DisablePartnerCall;
import com.shop2cn.iapi.sqdistributor.service.EnablePartnerCall;
import com.shop2cn.iapi.sqdistributor.service.SavePartnerConfigCall;

public class SqPartnerService {

	/**
	 * 设置合伙人配置
	 * @param merchantId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void savePartnerConfig(Long merchantId) throws ClientProtocolException,
			IOException {

		savePartnerConfig(merchantId, false);
	}
	
	public static void savePartnerConfig(Long merchantId, Boolean isZero)
			throws ClientProtocolException, IOException {

		SavePartnerConfigReq savePartnerConfigReq = new SavePartnerConfigReq();
		SavePartnerConfigCall savePartnerConfigCall = new SavePartnerConfigCall();

		savePartnerConfigReq.setMerchantId(merchantId);
		savePartnerConfigReq.setPartnerLevelIndex(0);
		savePartnerConfigReq.setPartnerLevelLabel("合伙人");
		
		if (isZero) {

			savePartnerConfigReq.setLayer1RewardRate(BigDecimal.ZERO);
			savePartnerConfigReq.setLayer2RewardRate(BigDecimal.ZERO);
		} else {

			savePartnerConfigReq.setLayer1RewardRate(new BigDecimal(String
					.valueOf(0.02d)));
			savePartnerConfigReq.setLayer2RewardRate(new BigDecimal(String
					.valueOf(0.01d)));
		}
		
		savePartnerConfigCall.setData(savePartnerConfigReq);
		savePartnerConfigCall.callService();
	}

	/**
	 * 分销员开启合伙人功能
	 * 
	 * @param merchantId
	 * @param partnerId
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void enablePartner(Long merchantId, Long partnerId)
			throws ClientProtocolException, IOException {

		EnablePartnerReq enablePartnerReq = new EnablePartnerReq();
		EnablePartnerCall enablePartnerCall = new EnablePartnerCall();

		enablePartnerReq.setMerchantId(merchantId);
		enablePartnerReq.setPartnerId(partnerId);

		enablePartnerCall.setData(enablePartnerReq);
		enablePartnerCall.callService();
	}
	
	/**
	 * 分销员关闭合伙人功能
	 * 
	 * @param merchantId
	 * @param partnerId
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void disablePartner(Long merchantId, Long partnerId)
			throws ClientProtocolException, IOException {

		DisablePartnerReq disablePartnerReq = new DisablePartnerReq();
		DisablePartnerCall disablePartnerCall = new DisablePartnerCall();

		disablePartnerReq.setMerchantId(merchantId);
		disablePartnerReq.setPartnerId(partnerId);

		disablePartnerCall.setData(disablePartnerReq);
		disablePartnerCall.callService();
	}
}
